package TokenRecognizer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jefoutta
 */
import java.util.*;

public class Sets<E>{

    private LinkedList<E> list;
    private LinkedList<String> listToString;
    private LinkedHashSet<String> set;
    private LinkedList<Integer> nlist;

    public Sets(){
        list = new LinkedList();
        set = new LinkedHashSet();
        listToString = new LinkedList();
    }

    public void add(E element){
        list.addLast(element);
        set.add(element.toString());
        listToString.add(element.toString());
    }

    public void addT(E element){
        Integer nelement = (Integer) element;
        Integer n = 0;
        for(int i = 0; i < list.size(); i++){
            Integer temp = (Integer) list.get(i);
            if(nelement > temp)
                n++;
        }
        list.add(n, element);
        set.add(element.toString());
        listToString.add(n,element.toString());
    }

    public void addT(Sets<E> tset){
        for(int i = 0; i < tset.getSize(); i++){
            if(!this.contains(tset.get(i)))
                this.addT(tset.get(i));
        }
    }

    public void add(Sets<E> tset){
        for(int i = 0; i < tset.getSize(); i++){
            if(!this.contains(tset.get(i)))
                this.add(tset.get(i));
        }
    }

    public boolean contains(E element){
        return set.contains(element.toString());
    }

    public E get(Integer index){
        return list.get(index);
    }

    public Integer indexOf(E e){
        return listToString.indexOf(e.toString());
    }

    public Integer getSize(){
        return set.size();
    }

    public void union(Sets<E> set2){
        for(int i =0; i < set2.getSize(); i++)
            if(!this.contains(set2.get(i)))
                this.add(set2.get(i));
    }

    public String toString(){
        return list.toString();
    }
}